import { _decorator, Component, instantiate, Node, Prefab, repeat } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('fireController')
export class fireController extends Component {
    @property(Node) fire:Node
    @property(Prefab) fire1:Prefab
    uplife:number
    SpeedY:number
    upTimer:number
    init()
    {
        this.SpeedY = 200
        this.uplife = Math.random() * 1.5 + 1.5;
        console.log(this.uplife)
    }
    start() {
        this.init();
        this.upOk();
    }
    upOk()
    {
        this.upTimer = setInterval(()=>
        {
            this.uplife -= 0.01
            if(this.uplife < 0)
            {
                this.fire.destroy();
                const fire1 = instantiate(this.fire1);
                this.node.addChild(fire1)
                clearInterval(this.upTimer)
            }
        },10)
    }
    up(deltaTime)
    {
        if(this.uplife>0)
        {
            const x = this.node.getPosition().x
            const y = this.node.getPosition().y
            this.node.setPosition(x,y + this.SpeedY * deltaTime);
        }
    }
    update(deltaTime: number) {
        this.up(deltaTime);
    }
}


